package com.customerlogin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.customerlogin.entity.FileCustomer;
import com.customerlogin.entity.JsonLogin;
import com.customerlogin.service.CustomerLoginService;
import com.entity.Customer;
import com.utils.JsonResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @Title: CustomerLoginController.java
 * @Package com.customerlogin.controller
 * @author 孙梦楠
 * @date 2017年10月26日 上午10:11:27
 * @version V1.0.0
 */
@Api(value = "111")
@RestController
@RequestMapping(value = "/login")
public class CustomerLoginController {

	@Autowired
	private CustomerLoginService customerloginservice;

	// 登录判断
	@ApiOperation(value = "登录判断", notes = "")
	@ApiImplicitParam(name = "customerwechat", value = "微信号", required = true, dataType = "String")
	@RequestMapping(value = "", method = RequestMethod.POST)
	public JsonResult<List<FileCustomer>> login(@RequestBody JsonLogin jsonLogin) {

		String wechatname = jsonLogin.getWechatname();
		String code = jsonLogin.getCode();

		return customerloginservice.login(wechatname, code);
	}

	// 绑定
	@ApiOperation(value = "绑定", notes = "")
	@ApiImplicitParam(name = "customer", value = "用户详细实体customer", required = true, dataType = "Customer")
	@RequestMapping(value = "/bind", method = RequestMethod.POST)
	public JsonResult<String> bind(@RequestBody JsonLogin jsonLogin) {

		String code = jsonLogin.getCode();
		String customeraccount = jsonLogin.getCustomeraccount();
		String wechatname = jsonLogin.getWechatname();

		return customerloginservice.bind(customeraccount, wechatname,code);
	}

//	// 解绑
//	@ApiOperation(value = "解绑", notes = "")
//	@ApiImplicitParam(name = "customer", value = "用户详细实体customer", required = true, dataType = "Customer")
//	@RequestMapping(value = "/unbind", method = RequestMethod.POST)
//	public JsonResult<String> unbind(@RequestBody Customer customer) {
//
//		String customerwechat = customer.getCustomerwechat();
//		String customeraccount = customer.getCustomeraccount();
//
//		return customerloginservice.unbind(customeraccount, customerwechat);
//	}

	@ApiOperation(value = "测试", notes = "")
	@RequestMapping(value = "/test", method = RequestMethod.GET)
	public JsonResult<String> test() {

		return customerloginservice.test();
	}

}
